package com.wiot;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.nio.NioDatagramChannel;

public class ServerApplication {

	private final NioEventLoopGroup group = new NioEventLoopGroup(2);
	
	public void init(){
		Bootstrap boot = new Bootstrap();
		try {
			boot.channel(NioDatagramChannel.class)
			.group(group)
			.option(ChannelOption.SO_BROADCAST, true)
			.handler(new ChannelInitializer<DatagramChannel>() {

				@Override
				protected void initChannel(DatagramChannel ch) throws Exception {
					// TODO Auto-generated method stub
					ChannelPipeline cp = ch.pipeline();
					cp.addLast(new WiotHandle());
				}
				
			})
			.bind(5680).sync().channel().closeFuture().sync();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			group.shutdownGracefully();
		}
	}
	
	public static void main(String[] args) {
		new ServerApplication().init();
	}
	
}
